package GUI;


import java.awt.*;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import Messages.MessageGetAllRecipes;
import Messages.MessageGetAllRecipesReply;
import Messages.MessageShowBusinessMenus;
import Messages.MessageShowBusinessMenusReply;
import Messages.MessageShowAllRecipesThatCanBuy;
import Messages.MessageShowAllRecipesThatCanBuyReply;
import Messages.MessageShowAllStandardsMenus;
import Messages.MessageShowAllStandardsMenusReply;
import Messages.MessageShowAllSuppliers;
import Messages.MessageShowAllSuppliersReply;
import Messages.MessageShowBusinessMenus;
import Messages.MessageShowBusinessMenusReply;

/**
 * this class create right panel with buttons for control of the menus of the restaurant(only for chief).This panel build after pressing on button
 * "ניהול תפריט" 
 */
public class PanelFunctionsManagementMenu  extends PanelFunctionsEmpty
{

	
	private static final long serialVersionUID = 1L;
	
	private JButton button_Menu;
	private JButton button_ListStandMenu;
	private JButton button_listRecipes;
	private JButton button_ListBussMenu;
	private JButton button_createRecipe;
	private JButton button_StandardMenu;
	
	private MainMenu mainMenu;
	private String GeneralMenu;
	
public PanelFunctionsManagementMenu(MainMenu mm)
{
	super();	
	this.mainMenu=mm;
	//this.add(get_button_Menu());
	this.add(get_button_listAllBusinessMenu());
	this.add(get_button_ListAllStandartMenu());
	this.add(get_button_ListAllRecipes());
	this.add(get_button_BuildNewMenu());
	this.add(get_button_BuildNewStandardMenu());
	this.add(get_button_createRecipe());
	
	
	GeneralMenu="1";
}
	
	
	
	
private JButton get_button_Menu() 
	{
		if (button_Menu == null) 
		{			
			button_Menu=new JButton("תפריט");  			 
			button_Menu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_Menu.setPreferredSize(new Dimension(220, 30));
			
			button_Menu.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					MessageShowAllRecipesThatCanBuy msgShowRecipes=new MessageShowAllRecipesThatCanBuy(GeneralMenu);
					
					try {
						mainMenu.ms.client.sendToServer(msgShowRecipes);
						MessageShowAllRecipesThatCanBuyReply resultMenu=(MessageShowAllRecipesThatCanBuyReply)mainMenu.ms.client.GetMessage();
						mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
						mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
						mainMenu.getContentPane().add(new PfShow_all_recipes_that_can_buy(mainMenu,resultMenu.getResultRecipes()), BorderLayout.CENTER);	
						mainMenu.getContentPane().add(new PanelFunctionsManagementMenu(mainMenu), BorderLayout.EAST);
						mainMenu.getContentPane().validate();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
					
					
					
					System.out.println("tables actionPerformed()"); 							
				}
			});
		}
		return button_Menu;
	}
	
	
	
	
private JButton get_button_ListAllStandartMenu() 
	{
	final Vector<String> arr = new Vector<String>();
		if (button_ListStandMenu == null) 
		{			
			button_ListStandMenu=new JButton("רשימת תפריטים רגילים"); 
			if(this.mainMenu.getUser().getPermission()!=3)
				button_ListStandMenu.setEnabled(false);
			button_ListStandMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_ListStandMenu.setPreferredSize(new Dimension(220, 30));
			
			button_ListStandMenu.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					
					MessageShowAllStandardsMenus msgShowMenu=new MessageShowAllStandardsMenus( );
					
					try {
						mainMenu.ms.client.sendToServer(msgShowMenu);
						MessageShowAllStandardsMenusReply resultMenu=(MessageShowAllStandardsMenusReply)mainMenu.ms.client.GetMessage();
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfSearch_standard_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					mainMenu.getContentPane().add(new PanelFunctionMenuAllStandartsMenu(mainMenu,arr), BorderLayout.EAST);
					mainMenu.getContentPane().validate();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				
			});
		}
		return button_ListStandMenu;
	}


private JButton get_button_BuildNewStandardMenu() 
{
	if (button_StandardMenu == null) 
	{			
		button_StandardMenu=new JButton("בניית תפריט רגיל חדש");  			 
		button_StandardMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_StandardMenu.setPreferredSize(new Dimension(220, 30));
		
		button_StandardMenu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
					
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
				mainMenu.getContentPane().add(new PFAddNewStandartMenu(mainMenu), BorderLayout.CENTER);	
				mainMenu.getContentPane().add(new PanelFunctionEmptyWithoutKeyboard(mainMenu), BorderLayout.EAST);
				mainMenu.getContentPane().validate();						
			}
		});
	}
	return button_StandardMenu;
}

private JButton get_button_ListAllRecipes() 
{
	
	 final Vector<String> arr = new Vector<String>();
	 //send it to class PanelFunctionListOfAllRecipes(right side panel) for to know that any recipe is not chosen yet(empty vector)	
	if (button_listRecipes == null) 
	{			
		button_listRecipes=new JButton("רשימת מתכונים");  		
		if(this.mainMenu.getUser().getPermission()!=3)
			button_listRecipes.setEnabled(false);
		button_listRecipes.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_listRecipes.setPreferredSize(new Dimension(220, 30));
		
		button_listRecipes.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				
				MessageGetAllRecipes msgShowMenu=new MessageGetAllRecipes( );
				
				try {
					mainMenu.ms.client.sendToServer(msgShowMenu);
					MessageGetAllRecipesReply resultMenu=(MessageGetAllRecipesReply)mainMenu.ms.client.GetMessage();
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().add(new PfShow_all_recipes(mainMenu,resultMenu.getRecipes()), BorderLayout.CENTER);	
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
				mainMenu.getContentPane().add(new PanelFunctionListOfAllRecipes(mainMenu, arr), BorderLayout.EAST);
				mainMenu.getContentPane().validate();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}
	return button_listRecipes;
}

private JButton get_button_createRecipe() 
{
	if (button_createRecipe == null) 
	{			
		button_createRecipe=new JButton("בניית מתכון חדש");  			 
		button_createRecipe.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_createRecipe.setPreferredSize(new Dimension(220, 30));
		
		button_createRecipe.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
				//mainMenu.getContentPane().add(new PfAdd_new_recipe(mainMenu), BorderLayout.CENTER);
				mainMenu.getContentPane().add(new PfAdd_new_recipe(mainMenu), BorderLayout.CENTER);
				mainMenu.getContentPane().add(new PanelFunctionsManagementMenu(mainMenu), BorderLayout.EAST);
				mainMenu.getContentPane().validate();						
			}
		});
	}
	return button_createRecipe;
}

private JButton get_button_listAllBusinessMenu() 
{
	final Vector<String> arr = new Vector<String>();
	if (button_ListBussMenu == null) 
	{			
		button_ListBussMenu=new JButton("רשימת תפריטים עסקיים"); 
		if(this.mainMenu.getUser().getPermission()!=3)
			button_ListBussMenu.setEnabled(false);
		button_ListBussMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_ListBussMenu.setPreferredSize(new Dimension(220, 30));
		
		button_ListBussMenu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				
				MessageShowBusinessMenus msgShowMenu=new MessageShowBusinessMenus( );
				
				try {
					mainMenu.ms.client.sendToServer(msgShowMenu);
					MessageShowBusinessMenusReply resultMenu=(MessageShowBusinessMenusReply)mainMenu.ms.client.GetMessage();
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfSearch_business_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
					mainMenu.getContentPane().add(new PanelFunctionMenuListAllBusMenu(mainMenu,arr), BorderLayout.EAST);
					mainMenu.getContentPane().validate();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				System.out.println("tables actionPerformed()"); 							
			}
		});
	}
	return button_ListBussMenu;
}
	
private JButton get_button_BuildNewMenu() 
{
	if (button_Menu == null) 
	{			
		button_Menu=new JButton("בניית תפריט עסקי חדש");  			 
		button_Menu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_Menu.setPreferredSize(new Dimension(220, 30));
		button_Menu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				//if(((BorderLayout) mainMenu.getContentPane().getLayout()).getLayoutComponent(new PfAdd_new_recipe(mainMenu),BorderLayout.CENTER).);
			//	System.out.println("DAAAAA");
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
				mainMenu.getContentPane().add(new PfAddNewBusinessMenu(mainMenu), BorderLayout.CENTER);	
				mainMenu.getContentPane().add(new PanelFunctionEmptyWithoutKeyboard(mainMenu), BorderLayout.EAST);
				mainMenu.getContentPane().validate();						
			}
		});
	}
	return button_Menu;
}
}